package com.mxchip.livestar.original.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ReplaceAddRemoveBroadcastReceiver extends BroadcastReceiver {

    public static final String UPDATE_ACTION = "android.intent.action.PACKAGE_REPLACED";

    // APP包名ID
    // public static final String PACKAGE_NAME = "com.mxchip.livestar";

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals(UPDATE_ACTION)) {
            String packageName = intent.getData().getEncodedSchemeSpecificPart();
            if (packageName.equals(context.getPackageName())) {
                Log.d("TAG", "SilentInstall in ReplaceAddRemoveBroadcastReceiver aa: " + Thread.currentThread());
                Log.d("TAG", "更新安装成功....." + packageName);
//                Toast.makeText(context, "更新安装成功" + packageName, Toast.LENGTH_LONG).show();
// 重新启动APP

                Intent intentToStart = context.getPackageManager().getLaunchIntentForPackage(packageName);

                // Intent intentToStart = new Intent(context, WelcomeActivity.class);
                intentToStart.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intentToStart);
            }
        }
    }
}